load("//tools:defaults.bzl", "jasmine_node_test", "sass_binary", "ts_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

package(default_visibility = ["//visibility:public"])

# Test theme used to ensure that our themes will compile using CSS variables in
# the palettes.
sass_binary(
    name = "test-css-variables-theme",
    testonly = True,
    src = "test-css-variables-theme.scss",
    deps = [
        "//src/material/core:theming_scss_lib",
    ],
)

# Sass binary which is used to ensure that our themes will compile with the
# pattern for configuring themes. For more information, inspect
# the `mat-light-theme` and `mat-dark-theme` theming functions.
sass_binary(
    name = "test-theming-api",
    testonly = True,
    src = "test-theming-api.scss",
    deps = [
        "//src/material/core:theming_scss_lib",
    ],
)

# Sass binary used to ensure that the theming bundle works as expected.
sass_binary(
    name = "test-theming-bundle",
    testonly = True,
    src = "test-theming-bundle.scss",
    deps = ["//src/material:sass_lib"],
)

# Sass binary that asserts that setting the font family for a typography config works as expected.
sass_binary(
    name = "test-typography-font-family",
    testonly = True,
    src = "test-typography-font-family.scss",
    deps = ["//src/material:sass_lib"],
)

build_test(
    name = "sass_compile_tests",
    targets = [
        ":test-css-variables-theme",
        ":test-theming-api",
        ":test-theming-bundle",
        ":test-typography-font-family",
    ],
)

ts_library(
    name = "unit_test_lib",
    testonly = True,
    srcs = glob([
        "*.spec.ts",
    ]),
    # TODO(ESM): remove this once the Bazel NodeJS rules can handle ESM with `nodejs_binary`.
    devmode_module = "commonjs",
    deps = [
        "//tools/postcss",
        "//tools/sass:sass_lib",
        "@npm//@bazel/runfiles",
        "@npm//@types/jasmine",
        "@npm//@types/node",
        "@npm//postcss",
        "@npm//sass",
    ],
)

jasmine_node_test(
    name = "unit_tests",
    srcs = [":unit_test_lib"],
    data = [
        "//src/material:sass_lib",
        "//src/material-experimental:sass_lib",
    ],
    shard_count = 4,
)
